package com.example.testdemo;



import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * 锁的降级机制
 *
 *          写锁降级为读锁
 */
public class DemoThread {

    public static void main(String[] args) {


       ReadWriteLock lock=new ReentrantReadWriteLock();

       //写锁
        Lock wlock= lock.writeLock();

        //读锁
        Lock rlock=lock.readLock();

        wlock.lock();
        System.out.println("======wlock begin");

        rlock.lock();
        System.out.println("=======rlock begin");


        wlock.unlock();

        rlock.unlock();

    }
}
